package 第十周.homework;

public class DVDcollection {
    public DVDNode list;

    //Sets up an intially empty list of DVDs.
    public DVDcollection() {
        list = null;
    }

    //Creates a new DVDNode object and adds it to the end of the linked list.
    public void add(DVD d) {
        DVDNode node = new DVDNode(d);
        DVDNode current;

        if(list == null)
            list = node;
        else
        {
            current = list;
            while(current.next!=null)
                current = current.next;
            current.next = node;
        }
    }
    public String toString()
    {
        String result = "";
        DVDNode current = list;
        while(current != null)
        {
            result += current.dvd + "\n";
            current = current.next;
        }
        return result;
    }

    private class DVDNode {
        public DVD dvd;
        public DVDNode next;

        public DVDNode(DVD d) {
            dvd = d;
            next = null;
        }
    }
}